How can I accomplish this? If the system calls my code, what is the current
GrafPort (or how can I get one)? I tried creating my own GrafPort, but it
didn't work.
A
Avoid patching anything, if at all possible -- especially _GetNextEvent. You
can install a JGNEFilter procedure to check for system activity.
The current GrafPort is a QuickDraw global, and QuickDraw globals are part of the A5 world. Since your screen saver is stand-alone code, and you don't have your own A5 world, you can't obtain the current GrafPort. If you attempt to, you are likely to get a window or dialog GrafPort, probably from the front-most application. This isn't much use in a screen saver, as you can save only the portion of the screen where the window or dialog is drawn.
To avoid the GrafPort problem, you could construct your own A5 world, but this approach will quickly transform your "simple screen saver" into a technical nightmare that would have an even greater compatibility risk than your present code does. For more information on JGNEFilter, see Technote 1060, Controlling Apps with Synthesized Events, or jGNEFilter -- the Untold Story.
One approach is to launch an application that creates a window over the entire
screen. Since the amount of time it takes to activate a screen saver isn't
critical, you could do this when it's time for your screen saver to take
control, or you could have it constantly running in the background, and send it
to the front. Once your application is in the foreground, you can safely draw
anything you want on the screen. To restore the screen, simply close the
application, or send it to the background.